import PowerUp from './PowerUp.js'

// 额外生命道具类
export default class LifePowerUp extends PowerUp {
  constructor(x, y) {
    super(x, y, 'life')
    this.rotationSpeed = 0.03 // 较慢的旋转
    this.scaleDirection = 0.008 // 较明显的脉动
  }

  loadImage() {
    // 加载额外生命道具图像
    this.image.src =
      ''
  }

  // 获取光晕颜色
  getGlowColor() {
    return `rgba(255, 0, 85, ${this.glowOpacity})`
  }

  apply(player, game) {
    super.apply(player, game)

    // 增加玩家生命值
    game.lives++

    // 更新UI
    game.updateUI()

    // 显示提示信息
    game.showMessage('获得额外生命！', 2000)

    // 添加心跳动画效果
    this.addHeartbeatEffect(game)
  }

  // 添加心跳动画效果
  addHeartbeatEffect(game) {
    // 创建一个心形图案在屏幕上跳动
    const heartbeat = {
      x: game.canvas.width / 2,
      y: game.canvas.height / 2,
      scale: 1,
      opacity: 1,
      growDirection: 0.1,
      update: function () {
        this.scale += this.growDirection
        this.opacity -= 0.02

        if (this.scale > 2) {
          this.growDirection = -0.05
        }

        return this.opacity > 0
      },
      render: function (ctx) {
        const size = 50 * this.scale

        ctx.save()
        ctx.globalAlpha = this.opacity
        ctx.translate(this.x, this.y)
        ctx.scale(this.scale, this.scale)

        // 绘制心形
        ctx.beginPath()
        ctx.moveTo(0, 0)
        ctx.bezierCurveTo(-25, -25, -25, 25, 0, 40)
        ctx.bezierCurveTo(25, 25, 25, -25, 0, 0)
        ctx.fillStyle = '#ff0055'
        ctx.fill()

        ctx.restore()
      },
    }

    // 添加到游戏特效中
    game.addSpecialEffect(heartbeat)
  }
}
